const express = require('express')
const app = express()
const config = require('./src/app/config')
const user = require('./src/router/user')
const address = require('./src/router/address')
const home = require('./src/router/home')
const search = require('./src/router/search')
const detail = require('./src/router/detail')
const cart = require('./src/router/cart')
const order = require('./src/router/order')
/*
  GET    加载数据
  POST   添加数据
  PUT    添加或修改数据
  PATCH  修改数据
  DELETE 删除数据
  OPTION 浏览器自动发送，检查请求的权限
*/

app.use(express.urlencoded({ extended: true }))
// 解析json格式请求体的中间件
app.use(express.json())

app.use((req, res, next) => {
  // 设置响应头
  res.setHeader("Access-Control-Allow-Origin", "*")
  res.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE")
  res.setHeader("Access-Control-Allow-Headers", "Content-type")
  next()
})

app.use('/user', user)

app.use('/address', address)

app.use('/home', home)

app.use('/search', search)

app.use('/detail', detail)

app.use('/cart', cart)

app.use('/order', order)

app.listen(config.APP_PORT, () => {
  console.log(`服务器已启动,端口号：${config.APP_PORT}`);
})